﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using jajaja;
using Microsoft.Xna.Framework;

namespace tetrox_3D
{
    class piece
    {
        public Vector2 Position;

        private List<piece> _fifoPieces;
        public List<piece> fifoPieces
        {
            get { return _fifoPieces; }
            set { _fifoPieces = value; }
        }
        
        private List<voxel> _Voxels;
        public List<voxel> Voxels
        {
            get { return _Voxels; }
            set { _Voxels = value; }
        }
        private Type _TypePiece;

        public Type TypePiece
        {
            get { return _TypePiece; }
            set { _TypePiece = value; }
        }
        
        public List<voxel> AbsoluteVoxels()
        {
            List<voxel> prout = new List<voxel>();
            voxel temp;
            foreach (var item in this.Voxels)
            {
                temp = new voxel();
                temp.Couleur = item.Couleur;
                temp.position = new Vector3(this.Position.X * 10 + item.position.X * 10, this.Position.Y * 10 + item.position.Y * 10, 0);
                prout.Add(temp);
            }
            return prout;
        }

        public piece()
        {
            this._Voxels = new List<voxel>();
            this.Position = new Vector2(0, 0);
        }
        public piece(Type typePiece):this()
        {
            this.TypePiece = typePiece;
            voxel v1 = new voxel();
            voxel v2 = new voxel();
            voxel v3 = new voxel();
            voxel v4 = new voxel();

            switch (typePiece)
            {
                case Type.l1:
                    v1.Couleur = Color.Orange;
                    v2.Couleur = Color.Orange;
                    v3.Couleur = Color.Orange;
                    v4.Couleur = Color.Orange;
                    v1.position = new Vector3(0, 0, 0);
                    v2.position = new Vector3(0, 1, 0);
                    v3.position = new Vector3(0, 2, 0);
                    v4.position = new Vector3(1, 2, 0);
                    break;
                case Type.l2:
                    v1.Couleur = Color.Blue;
                    v2.Couleur = Color.Blue;
                    v3.Couleur = Color.Blue;
                    v4.Couleur = Color.Blue;
                    v1.position = new Vector3(1, 0, 0);
                    v2.position = new Vector3(1, 1, 0);
                    v3.position = new Vector3(1, 2, 0);
                    v4.position = new Vector3(0, 2, 0);
                    break;
                case Type.t:
                    v1.Couleur = Color.Purple;
                    v2.Couleur = Color.Purple;
                    v3.Couleur = Color.Purple;
                    v4.Couleur = Color.Purple;
                    v1.position = new Vector3(1, 0, 0);
                    v2.position = new Vector3(0, 1, 0);
                    v3.position = new Vector3(1, 1, 0);
                    v4.position = new Vector3(2, 1, 0);
                    break;
                case Type.s1:
                    v1.Couleur = Color.Green;
                    v2.Couleur = Color.Green;
                    v3.Couleur = Color.Green;
                    v4.Couleur = Color.Green;
                    v1.position = new Vector3(2, 0, 0);
                    v2.position = new Vector3(1, 0, 0);
                    v3.position = new Vector3(1, 1, 0);
                    v4.position = new Vector3(0, 1, 0);
                    break;
                case Type.s2:
                    v1.Couleur = Color.Red;
                    v2.Couleur = Color.Red;
                    v3.Couleur = Color.Red;
                    v4.Couleur = Color.Red;
                    v1.position = new Vector3(0, 0, 0);
                    v2.position = new Vector3(1, 0, 0);
                    v3.position = new Vector3(1, 1, 0);
                    v4.position = new Vector3(2, 1, 0);
                    break;
                case Type.barre:
                    v1.Couleur = Color.Cyan;
                    v2.Couleur = Color.Cyan;
                    v3.Couleur = Color.Cyan;
                    v4.Couleur = Color.Cyan;
                    v1.position = new Vector3(0, 1, 0);
                    v2.position = new Vector3(1, 1, 0);
                    v3.position = new Vector3(2, 1, 0);
                    v4.position = new Vector3(3, 1, 0);
                    break;
                case Type.carre:
                    v1.Couleur = Color.Yellow;
                    v2.Couleur = Color.Yellow;
                    v3.Couleur = Color.Yellow;
                    v4.Couleur = Color.Yellow;
                    v1.position = new Vector3(1, 1, 0);
                    v2.position = new Vector3(2, 1, 0);
                    v3.position = new Vector3(1, 2, 0);
                    v4.position = new Vector3(2, 2, 0);
                    break;
                default:
                    break;       
            }
            //v1.Couleur = new Color(243, 120, 0, 0.5f);
            //v2.Couleur = new Color(243, 120, 0, 0.5f);
            //v3.Couleur = new Color(243, 120, 0, 0.5f);
            //v4.Couleur = new Color(243, 120, 0, 0.5f);
            this.Voxels.Add(v1);
            this.Voxels.Add(v2);
            this.Voxels.Add(v3);
            this.Voxels.Add(v4);
        }
    }
}
